"Osax" stands for Open Scripting Architecture eXtension, the other name for "scripting addition."
Some of the functions of Smile, together with some additional functionalities, have been compiled into an independent scripting addition : Satimage osax. You can of course use the functions that it provides, independently of using Smile.
The Satimage osax must be installed for Smile to be fully functional.
Using the "Open dictionary" command of the "File" menu, you can open the dictionary of the Satimage osax. (Note : the "Open dictionary" command can also be used to open the dictionary of any installed scripting addition (osax).) The present help file introduces this osax with additional details and examples. Please refer to the Satimage osax dictionary itself for the syntax of any command.
The commands of the Satimage osax are given below in a thematic order : strings, lists and records, files, resources, and maths.
Reminder : To try the below example scripts for yourself, open an output window associated with this help file. Any results occurring from running the script will then appear in the output window, rather than being appended at the end of this help file window.
String manipulation
• extract string : extract a substring
Negative indexes start from the end (far right side) of the string.
Sample
----------------------------
set theTime to "12:34:56"
set theSeconds to extract string theTime from -2 to -1
-- "56"
----------------------------
• uppercase : move to upper case
Uppercase is useful to make case insensitive searches or comparisons.
Sample
----------------------------
set theName to "AppleScript"
set theName to uppercase theName
-- "APPLESCRIPT"
----------------------------
• replace : replace all occurences of a substring
Sample
----------------------------
set theString to "12:34:56"
set theFileName to replace ":" by "-" in theString
-- "12-34-56"
----------------------------
• format : format a real number into a string
If the real number does not fit the format string, a standard format will be used. It may use the decimal notation.
Sample
----------------------------
format pi into "###000.0000'...'"
-- "003.1416..."
----------------------------
Lists and records manipulation
• concat : concatenates records, using a sum rule on the items
Sample
----------------------------
set theStore to {books:12, pens:{black:50, green:50}, copybooks:3}
set theDelivery to {books:5, pens:{black:50, red:20}, eraser:1}
• suppress item : delete an item from a list or a record
Depending if a key in a record is user-defined or defined by the application (or AppleScript), you need or need not enclose its title between quotes.
Samples
----------------------------
set theG3s to {"Blue", "White", "Beige"}
set theNewG3 to suppress item -1 from theG3s
-- {"Blue", "White"}
----------------------------
----------------------------
set theStore to {books:12, pens:{black:50, green:50}, copybooks:3}
set thePaper to suppress item "pens" from theStore -- pens is a user property
-- {books:12, copybooks:3}
----------------------------
----------------------------
set theRecord to {name:"Bob", age:33}
set theAge to suppress item name from theRecord -- name is pre-defined
-- {age:33}
----------------------------
File management
• applicationpath : find an application file (or application files) given a creator type in a given volume
When the "list all" argument is false, the command returns the last modified application with the given creator type in the given volume. This may be or not be the way "Finder" chooses what application it will open when you double-click a document - in the case where several applications with the same creator type are on the same volume.
• get alias info for : returns a list of 3 strings, the names of the AppleTalk zone, of the machine, and of the volume, a given file (or alias) belongs to.
This command is intended, among other things, to provide some workaround to a deep bug of the "Finder", namely its unability to distinguish properly in AppleScript between different file specifications with the same name when they are on the Desktop.
Sample
----------------------------
remote info for alias (my path name)
-- {"RedZone", "G4/800", "160GB HD"}
----------------------------
• backup : synchronizes 2 folders
The arguments of the command can be aliases of folders, instead of folders.
The output of this command, in level 0 (resp. 2), lists the files to be (resp. which have been) modified or created. As the comments are in French, you need know that "Eléments mis à jour" means updating, "Eléments créés" means creating, and "RAS" means "nothing to report".
Comments
The dictionary mentions that the "backup" command is not entirely safe. So far, the only known bug concerns the backup of empty folders. It is not known as possibly inducing data loss.
General form
----------------------------
backup <pathname of source folder> onto <pathname of target folder> level 2
-- returns the lists of the created / modified folders / files
----------------------------
Resource management
The Satimage osax provides facilities to read and write resources from / to the resource fork of a file. This can prove useful for a lot of technical operations on your Macintosh.
• LoadResource : get a resource of a specified type and id number from a specified file
Sample
----------------------------
LoadResource 4000 type "STR " from "" & (path to system folder) & "Finder"
-- "About This Computer…"
----------------------------
• ListResources : get the list of the id numbers of resources of a specified type a the specified file
Sample
----------------------------
ListResources "PICT" from "" & (path to system folder) & "Finder"
-- {4000, 4001}
----------------------------
• GetResourceName : get the name of a resource of specified type and id number from the specified file
Sample
----------------------------
GetResourceName 6 type "CODE" from "" & (path to system folder) & "Finder"
-- "CFM Launch"
----------------------------
• PutResource : write the given resource to the specified file with specified type and id number
This command will write to the disk, and will erase any existing resource of the specified file with the same type and the same id number. If you make a mistake, this can mean data loss.
Sample
----------------------------
set theRect to {20,40,120,140}
PutResource theRect index 128 type "qdrt" to (new file)
• The default name given to a resource by "PutResource" is the four character code of the AppleScript data type. "LoadResource" uses this name to coerce the data stored in the resource into the AppleScript type, except if you force coercion by a call to "LoadResource … as …". Thus you should not give a four character name to a resource unless you know what you are doing.
You can use this feature to force the type of the data. For instance, if you store a list of four integers with :
----------------------------
PutResource theRect index 128 type "qdrt" to MyFile
----------------------------
then the corresponding "LoadResource" will create a QuickDraw bounds type.
• "LoadResource" is particularly useful for storing scripts. When you want to load a script which is stored in the resource fork, always force the coercion into a fake type, such as :
----------------------------
LoadResource 129 type "scpt" from MyFile as "foo "
----------------------------
Otherwise, "LoadResource" will return, not the script, but the result of the script, that is, the returned value of the "run" handler of the script.
When storing a script in the resource fork (by "PutResource"), always give it a name which does not have four characters.